Danish updates from David Munch
[adiumx.git] / Plugins / Purple Service / adiumPurpleAccounts.m
blob522422583393536039dbeda40d257a449b105eaf
1 //
2 //  adiumPurpleAccounts.m
3 //  Adium
4 //
5 //  Created by Evan Schoenberg on 12/3/06.
6 //
8 #import "adiumPurpleAccounts.h"
9 #import <Adium/AIContactControllerProtocol.h>
11 /* A buddy we already have added us to their buddy list. */
12 static void adiumPurpleAccountNotifyAdded(PurpleAccount *account, const char *remote_user,
13                                                          const char *id, const char *alias,
14                                                          const char *message)
16         
19 static void adiumPurpleAccountStatusChanged(PurpleAccount *account, PurpleStatus *status)
21         
24 /* Someone we don't have on our list added us. Will prompt to add them. */
25 static void adiumPurpleAccountRequestAdd(PurpleAccount *account, const char *remote_user,
26                                         const char *accountID, const char *alias,
27                                         const char *message)
29 #warning Something is better than nothing, but we should display a message which includes message and alias
30         /* purple displays something like "Add remote_user to your list? remote_user (alias) has made accountID his buddy." */
31         [accountLookup(account) requestAddContactWithUID:[NSString stringWithUTF8String:remote_user]];
35  * @brief A contact requests authorization to add us to her list
36  *
37  * @param account PurpleAccount being added
38  * @param remote_user The UID of the contact
39  * @param anId May be NULL; an ID associated with the authorization request (?)
40  * @param alias The contact's alias. May be NULL.
41  * @param mess A message accompanying the request. May be NULL.
42  * @param authorize_cb Call if authorization granted
43  * @param deny_cb Call if authroization denied
44  * @param user_data Data for the process; be sure to return it in the callback
45  */
46 static void *adiumPurpleAccountRequestAuthorize(PurpleAccount *account, const char *remote_user, const char *anId,
47                                                                                 const char *alias, const char *message, 
48                                                                                 gboolean on_list, PurpleAccountRequestAuthorizationCb authorize_cb, PurpleAccountRequestAuthorizationCb deny_cb,
49                                                                                 void *user_data)
51         NSMutableDictionary     *infoDict = [NSMutableDictionary dictionaryWithObjectsAndKeys:
52                 [NSString stringWithUTF8String:remote_user], @"Remote Name",
53                 [NSValue valueWithPointer:authorize_cb], @"authorizeCB",
54                 [NSValue valueWithPointer:deny_cb], @"denyCB",
55                 [NSValue valueWithPointer:user_data], @"userData",
56                 nil];
57         
58         if (message && strlen(message)) [infoDict setObject:[NSString stringWithUTF8String:message] forKey:@"Reason"];
60         return [accountLookup(account) authorizationRequestWithDict:infoDict];;
63 static void adiumPurpleAccountRequestClose(void *ui_handle)
65         id      ourHandle = (id)ui_handle;
67         if ([ourHandle respondsToSelector:@selector(purpleRequestClose)]) {
68                 [ourHandle performSelector:@selector(purpleRequestClose)];
69                 
70         } else if ([ourHandle respondsToSelector:@selector(closeWindow:)]) {
71                 [ourHandle performSelector:@selector(closeWindow:)
72                                                 withObject:nil];
73         }
76 void adiumPurpleAccountRegisterCb(PurpleAccount *account, gboolean succeeded, void *user_data) {
77         id ourHandle = user_data;
78         
79         if([ourHandle respondsToSelector:@selector(purpleAccountRegistered:)])
80                 [ourHandle purpleAccountRegistered:(succeeded ? YES : NO)];
83 static PurpleAccountUiOps adiumPurpleAccountOps = {
84         &adiumPurpleAccountNotifyAdded,
85         &adiumPurpleAccountStatusChanged,
86         &adiumPurpleAccountRequestAdd,
87         &adiumPurpleAccountRequestAuthorize,
88         &adiumPurpleAccountRequestClose
91 PurpleAccountUiOps *adium_purple_accounts_get_ui_ops(void)
93         return &adiumPurpleAccountOps;